<?php
namespace Tbf\Bundle\CallbackSerializerBundle\Serializer;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Tbf\Bundle\SerializerBundle\Exception\SerializerException;
use Tbf\Bundle\SerializerBundle\Handler\ClassNameAwareHandlerInterface;
use Tbf\Bundle\SerializerBundle\Handler\NewFromArray\NewFromArrayInterface;
use Tbf\Bundle\SerializerBundle\Handler\ToArray\ToArrayInterface;
use Tbf\Bundle\SerializerBundle\Serializer;
use Tbf\Bundle\CallbackSerializerBundle\Wrapper\DicServiceWrapper;
use Tbf\Bundle\SerializerBundle\SerializerAware;

class DisServiceWrapperSerializer implements ToArrayInterface,NewFromArrayInterface,ClassNameAwareHandlerInterface{
    protected $container;
    function __construct(ContainerInterface $container){
        $this->container = $container;
    }
    public function toArray($obj,$group=null)
    {
        /** @var \Tbf\Bundle\CallbackSerializerBundle\Wrapper\DicServiceWrapper $obj */
        return array(
            'function_name'=>$obj->getFunctionName(),
            'service_id'=>$obj->getServiceId(),
        );
    }

    public function newFromArray($class_name, $input,$group=null)
    {
        $obj = new DicServiceWrapper($input['service_id'],$input['function_name']);
        $obj->setContainer($this->container);
        return $obj;
    }

    /**
     * @return string
     */
    static function getSerializeClassName()
    {
        return '\Tbf\Bundle\CallbackSerializerBundle\Wrapper\DicServiceWrapper';
    }

}